package com.njsf.service.impl;

import com.njsf.dao.UserMapper;
import com.njsf.dto.ResponseJson;
import com.njsf.pojo.User;
import com.njsf.service.UserService;
import com.njsf.utils.MD5Util;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public ResponseJson checkLogin(String username, String pwd , HttpServletRequest request) {
        ResponseJson responseJson = null;
        User user = userMapper.findByNameAndPwd(username, MD5Util.MD5(pwd));
        if (user != null){
            responseJson = new ResponseJson(100,"登录成功!");
            request.getSession().setAttribute("user",user);
        }else{
            responseJson = new ResponseJson(101,"登录失败!");
        }
        return responseJson;
    }
<<<<<<< HEAD
=======

    @Override
    public ResponseJson addUser(User user) {
        ResponseJson responseJson = null;
        if (!user.getUsername().equals("")){
            int flag = userMapper.addUser(user);
            if (flag != 0){
                responseJson = new ResponseJson(100,"注册成功!");
            }else{
                responseJson = new ResponseJson(101,"注册失败!");
            }
        }else {
            responseJson = new ResponseJson(101,"注册失败!");
        }
        return responseJson;
    }

    @Override
    public ResponseJson selectByUsername(String username) {
        ResponseJson responseJson = null;
        User user = userMapper.findByUsername(username);
        if (user != null){
            responseJson = new ResponseJson(101,"用户名已经存在，请重新输入!");
        }else{
            responseJson = new ResponseJson(100,"用户名可以使用!");
        }
        return responseJson;
    }

    @Override
    public int activeUserByActiveCode(String activeCode) {
        int flag = userMapper.activeUser(activeCode);
        return flag;
    }
>>>>>>> 180ace60693232df69575b4f82fc34aeb3fc90e8
}
